package com.mofang.ticketing.common.core.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author LGC
 * @date 2022/1/26 11:36
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum ResultCode implements IResultCode, Serializable {
    /**
     *
     */
    SUCCESS("200", "成功"),
    ERROR("-200", "系统执行出错"),
    UPDATE_ERROR("-201", "修改失败，请重试"),

    USER_LOGIN_ERROR("A1001", "用户登录异常"),
    USER_NOT_EXIST("A1002", "用户不存在"),
    USER_ACCOUNT_LOCKED("A1003", "用户账户被冻结"),
    USER_ACCOUNT_INVALID("A1004", "用户账户已作废"),

    USERNAME_OR_PASSWORD_ERROR("A1005", "用户名或密码错误"),
    TOKEN_INVALID_OR_EXPIRED("A1006", "token无效或已过期"),

    PARAM_ERROR("A1007", "请求参数错误 "),

    RESOURCE_NOT_FOUND("A1008", "请求资源不存在"),
    PARAM_IS_NULL("A1009", "请求必填参数为空"),

    ACCESS_PERMISSION_ERROR("A1010", "访问权限异常"),
    ACCESS_UNAUTHORIZED("A1012", "访问未授权"),
    SERVICE_FALLBACK("A1013", "服务器繁忙，请稍后再试"),
    BASE_UPLOAD_FILE_ERROR("A1014", "上传文件失败"),
    BASE_DEL_FILE_ERROR("A1015", "删除文件失败"),

    PWD_ERROR("A1016", "密码错误"),
    NOT_OPERATE("A1017", "数据不能操作"),

    EXPORT_EXCEL_ERROR("A1018", "导出失败"),
    EXPORT_EXCEL_SIZE_ZERO("A1019", "本次导出条数0"),
    SIGN_ERROR("A1020", "验签失败"),

    IP_ERROR("B0001", "当前账号被锁定,请30分钟后重试"),
    RE_VERIFICATION_EXPIRED("B0002", "验证码已过期"),
    RE_VERIFICATION_ERROR("B0003", "验证码错误:{}"),
    ;

    private String code;

    @Setter
    private String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }

    public static ResultCode getValue(String code) {
        for (ResultCode resultCode : values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return ERROR;
    }
}
